package com.cesce.batch.cobros.items;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.item.ItemProcessor;

import com.cesce.batch.cobros.reverse.Cobregistro;
import com.cesce.batch.cobros.util.Constantes;




public class BackupCsvProcessor implements ItemProcessor<Cobregistro, Cobregistro> {

	protected final Log logger = LogFactory.getLog(getClass());

	
	public Cobregistro process(Cobregistro item) throws Exception {
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		
    	File srcFile= new File(item.getIdregistro() + Constantes.PREFIX_UNIFIED_CSV);
    	File destFile= new File(Constantes.PATH_UNIFIED_CSV + item.getIdregistro() + "_cobros_" + item.getFechanotificacion() + "_" + sdf.format(new Date()) + ".csv");    	
    	FileUtils.copyFile(srcFile, destFile);
    	srcFile.delete();
		
		return item;
	}
	
	
}
